package com.itwn.portal.mapper;

import com.itwn.portal.entity.Section;
import com.itwn.portal.vo.SectionReadVo;
import com.itwn.portal.vo.SectionVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
@Repository
public interface SectionMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Section record);

    Section selectByPrimaryKey(Integer id);

    List<Section> selectAll();

    int updateByPrimaryKey(Section record);

    //根据resoursid查询最新更新章节
    Section selectNewestSectionByResoursId(Integer id);

    List<SectionVo> selectSectionByTime(@Param("startTime") Date startTime,
                                        @Param("endTime") Date endTime,
                                        @Param("num") Integer num);

    @Select("select * from t_section where resource_id = #{value} ORDER BY id")
    List<Section> selectAllById(Integer id);

    @Select("SELECT * from(select * from t_section WHERE resource_id=#{value} ORDER BY id desc limit 20 ) aa\n" +
            "ORDER BY id ")
    List<Section> selectLatest(Integer id);

    SectionReadVo selectSectionReadVo(@Param("rid") Integer rid, @Param("sid") Integer sid);

    Integer selectNextSectionid(@Param("rid") Integer rid,@Param("sid") Integer sid);
}